package domain.entities;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Involucrado entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "involucrado", catalog = "bms")
public class Involucrado implements java.io.Serializable {

    // Fields

    private Integer id;
    private String cuit;
    private String cnpj;
    private String nit;
    private String rut;

    private String eclipseId;
    private DoctorDegree degree;
    private String email;
    private String mobilePhone;
    private String nextelNumber;
    private String nombre;
    private String apellido;
    private String phone;
    private String position;
    private Compromisopais compromisopais;
    private Centro centro;
    private Boolean isDoctor;
    private TherapeuticArea therapeuticArea;
    private Specialty speciality;
    private String fax;
    private Collection<InvestigadorProtocoloCentro> centrosAsPrincipal;
    private Collection<InvestigadorProtocoloCentro> centrosAsSub;
    private Set<CdaMolecula> cdaMoleculas = new HashSet<CdaMolecula>(0);

    private byte[] file;    //CV Spanish
    private byte[] fileEnglish;    //CV Spanish
    private String filename; //CV English
    private String filenameEnglish; //CV English

    // Constructors

    /** default constructor */
    public Involucrado() {
    }

    /** minimal constructor */
    public Involucrado(String nombre) {
        this.nombre = nombre;
    }

    /** full constructor */
    public Involucrado(Integer id, String cuit, DoctorDegree degree, String email, String mobilePhone, String nombre, String apellido, String phone, String position, Centro centro, String fax, Set<CdaMolecula> cdaMoleculas, Set<Protocolscorecard> protocolscorecards) {
        this.id = id;
        this.cuit = cuit;
        this.degree = degree;
        this.email = email;
        this.mobilePhone = mobilePhone;
        this.nombre = nombre;
        this.apellido = apellido;
        this.phone = phone;
        this.position = position;
        this.centro = centro;
        this.fax = fax;
        this.cdaMoleculas = cdaMoleculas;
    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "cuit")
    public String getCuit() {
        return this.cuit;
    }

    public void setCuit(String cuit) {
        this.cuit = cuit;
    }

    @Column(name = "cnpj")
    public String getCnpj() {
        return this.cnpj;
    }

    public void setCnpj(String cnpj) {
        this.cnpj = cnpj;
    }

    @Column(name = "nit")
    public String getNit() {
        return this.nit;
    }

    public void setNit(String nit) {
        this.nit = nit;
    }

    @Column(name = "rut")
    public String getRut() {
        return this.rut;
    }

    public void setRut(String rut) {
        this.rut = rut;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    public DoctorDegree getDegree() {
        return this.degree;
    }

    public void setDegree(DoctorDegree degree) {
        this.degree = degree;
    }

    @Column(name = "email")
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "mobilePhone")
    public String getMobilePhone() {
        return this.mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    @Column(name = "nombre", nullable = false)
    public String getNombre() {
        return this.nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    @Column(name = "phone")
    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Column(name = "position")
    public String getPosition() {
        return this.position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "involucrado")
    @LazyCollection(LazyCollectionOption.FALSE)
    public Set<CdaMolecula> getCdaMoleculas() {
        return this.cdaMoleculas;
    }

    public void setCdaMoleculas(Set<CdaMolecula> cdaMoleculas) {
        this.cdaMoleculas = cdaMoleculas;
    }

    @Column(name = "apellido")
    public String getApellido() {
        return apellido;
    }

    public void setApellido(String apellido) {
        this.apellido = apellido;
    }

    @Column(name = "nextel_number")
    public String getNextelNumber() {
        return nextelNumber;
    }

    public void setNextelNumber(String nextelNumber) {
        this.nextelNumber = nextelNumber;
    }

    @ManyToOne()
    @LazyCollection(LazyCollectionOption.FALSE)
    @JoinColumn(name = "CENTROid")
    public Centro getCentro() {
        return this.centro;
    }

    public void setCentro(Centro centro) {
        this.centro = centro;
    }

    @Column(name = "fax")
    public String getFax() {
        return this.fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    public TherapeuticArea getTherapeuticArea() {
        return therapeuticArea;
    }

    public void setTherapeuticArea(TherapeuticArea therapeuticArea) {
        this.therapeuticArea = therapeuticArea;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    public Specialty getSpeciality() {
        return speciality;
    }

    public void setSpeciality(Specialty speciality) {
        this.speciality = speciality;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "principalInvestigator")
    @LazyCollection(LazyCollectionOption.FALSE)
    public Collection<InvestigadorProtocoloCentro> getCentrosAsPrincipal() {
        return centrosAsPrincipal;
    }

    public void setCentrosAsPrincipal(Collection<InvestigadorProtocoloCentro> centrosAsPrincipal) {
        this.centrosAsPrincipal = centrosAsPrincipal;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "subInvestigator")
    @LazyCollection(LazyCollectionOption.FALSE)
    public Collection<InvestigadorProtocoloCentro> getCentrosAsSub() {
        return centrosAsSub;
    }

    public void setCentrosAsSub(Collection<InvestigadorProtocoloCentro> centrosAsSub) {
        this.centrosAsSub = centrosAsSub;
    }

    @Column(name = "eclipseId")
    public String getEclipseId() {
        return this.eclipseId;
    }

    public void setEclipseId(String eclipseId) {
        this.eclipseId = eclipseId;
    }

    @Column(name = "isDoctor")
    public Boolean getIsDoctor() {
        return isDoctor;
    }

    public void setIsDoctor(Boolean isDoctor) {
        this.isDoctor = isDoctor;
    }

    @Column(name = "file", columnDefinition = "LONGBLOB")
    public byte[] getFile() {
        return file;
    }

    public void setFile(byte[] file) {
        this.file = file;
    }

    @Column(name = "filename")
    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    @ManyToOne()
    public Compromisopais getCompromisopais() {
        return this.compromisopais;
    }

    public void setCompromisopais(Compromisopais compromisopais) {
        this.compromisopais = compromisopais;
    }

    @Transient
    public String getFullName(){
        return this.nombre + " " + this.apellido;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Involucrado)) return false;

        Involucrado that = (Involucrado) o;

        if (!id.equals(that.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Transient
    public boolean isNew()
    {
        return this.id == null;
    }

    public String getFilenameEnglish() {
        return filenameEnglish;
    }

    public void setFilenameEnglish(String filenameEnglish) {
        this.filenameEnglish = filenameEnglish;
    }
    @Column( columnDefinition = "LONGBLOB")
    public byte[] getFileEnglish() {
        return fileEnglish;
    }

    public void setFileEnglish(byte[] fileEnglish) {
        this.fileEnglish = fileEnglish;
    }
}